package weibo.acitivity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.whu.administrator.ws.MyApplication;
import com.whu.administrator.ws.R;
import com.whu.administrator.ws.UIHandler;

import model.Blog;
import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * Created by Administrator on 2016/4/1.
 */
public class MyPhotoActivity extends UIHandler.BaseActivity {

    ImageView imageView;
    PhotoViewAttacher mAttacher;

    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.defalut_img) //设置图片在下载期间显示的图片
            .showImageForEmptyUri(R.drawable.defalut_img)//设置图片Uri为空或是错误的时候显示的图片
            .showImageOnFail(R.drawable.defalut_img)  //设置图片加载/解码过程中错误时候显示的图片
//    .cacheInMemory(true)//设置下载的图片是否缓存在内存中
            .cacheOnDisc(true)//设置下载的图片是否缓存在SD卡中
            .considerExifParams(true)  //是否考虑JPEG图像EXIF参数（旋转，翻转）
            .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)//设置图片以如何的编码方式显示
            .bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型//
            .resetViewBeforeLoading(true)//设置图片在下载前是否重置，复位
            .displayer(new RoundedBitmapDisplayer(20))//是否设置为圆角，弧度为多少
            .displayer(new FadeInBitmapDisplayer(100))//是否图片加载好后渐入的动画时间
            .build();//构建完成

    Blog blog;
    Integer position;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photoview);
        initview();
        initdata();
    }

    private void initdata() {
        blog = (Blog) getIntent().getSerializableExtra("blog");
        position = getIntent().getIntExtra("position", 0);

        String imge_set = blog.getImage_Set();
        String[] imgs = imge_set.split(";");

        String ip = MyApplication.share().getString(R.string.IP);
        ImageLoader.getInstance().displayImage("http://" + ip + "/Blog/DownloadFile?name=" + imgs[position], imageView, options, new SimpleImageLoadingListener() {
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                super.onLoadingComplete(imageUri, view, loadedImage);
                mAttacher.update();
            }
        });


    }

    private void initview() {
        imageView = (ImageView) findViewById(R.id.id_img);
        mAttacher = new PhotoViewAttacher(imageView);
    }
}
